﻿using UnityEngine;

namespace Yoozoo.Mars.Got.SpriteAnim
{
    public class SpriteFrameController
    {
        private Interface_AnimSpriteSupportTemplate interface_template;
        public SpriteFrameController(Interface_AnimSpriteSupportTemplate interface_template)
        {
            this.interface_template = interface_template;
        }

        public DIRCTION_INDEX_ENUM GetDirectionIndex(Vector3 moveVector)
        {
            return interface_template.GetDirectionIndex(moveVector);
        }
        
        public DIRCTION_INDEX_ENUM GetDirectionIndex16Direct(Vector3 moveVector)
        {
            return interface_template.GetDirectionIndex16Direct(moveVector);
        }
        
        public int GetFlipIndex(DIRCTION_INDEX_ENUM indexOld)
        {
            DIRCTION_INDEX_ENUM indexNew = indexOld;
            int directIndex = (int)indexOld;
            switch (indexNew)
            {
                case DIRCTION_INDEX_ENUM.LEFT_DOWN:
                    directIndex = 0;
                    break;
                case DIRCTION_INDEX_ENUM.LEFT:
                    directIndex = 4;
                    break;
                case DIRCTION_INDEX_ENUM.LEFT_UP:
                    directIndex = 3;
                    break;
                case DIRCTION_INDEX_ENUM.UP:
                    directIndex = 2;
                    break;
                case DIRCTION_INDEX_ENUM.RIGHT_UP:
                    directIndex = 3;
                    break;
                case DIRCTION_INDEX_ENUM.RIGHT:
                    directIndex = 4;
                    break;
            }
            return directIndex;
        }
        
        public int GetFlipIndex16Direct(DIRCTION_INDEX_ENUM indexOld)
        {
            int directIndex = (int)indexOld;
            switch (indexOld)
            {
                case DIRCTION_INDEX_ENUM.LEFT_DOWN:
                    directIndex = 0;
                    break;
                case DIRCTION_INDEX_ENUM.LEFT:
                    directIndex = 4;
                    break;
                case DIRCTION_INDEX_ENUM.LEFT_UP:
                    directIndex = 3;
                    break;
                case DIRCTION_INDEX_ENUM.UP:
                    directIndex = 2;
                    break;
                case DIRCTION_INDEX_ENUM.RIGHT_UP:
                    directIndex = 3;
                    break;
                case DIRCTION_INDEX_ENUM.RIGHT:
                    directIndex = 4;
                    break;
                case DIRCTION_INDEX_ENUM.RIGHT_MIDDLE_RIGHTDOWN:
                case DIRCTION_INDEX_ENUM.LEFTDOWN_MIDDLE_LEFT:
                    directIndex = 5;
                    break;
                case DIRCTION_INDEX_ENUM.RIGHTDOWN_MIDDLE_DOWN:
                case DIRCTION_INDEX_ENUM.DOWN_MIDDLE_LEFTDOWN:
                    directIndex = 6;
                    break;
                case DIRCTION_INDEX_ENUM.LEFT_MIDDLE_LEFTUP:
                case DIRCTION_INDEX_ENUM.RIGHTUP_MIDDLE_RIGHT:
                    directIndex = 8;
                    break;
                case DIRCTION_INDEX_ENUM.LEFTUP_MIDDLE_UP:
                case DIRCTION_INDEX_ENUM.UP_MIDDLE_RIGHTUP:
                    directIndex = 7;
                    break;
            }
            return directIndex;
        }

        public bool CheckFlip(int directionIndex)
        {
            DIRCTION_INDEX_ENUM indexNew = (DIRCTION_INDEX_ENUM)directionIndex;
            //int directIndex = directionIndex;
            switch (indexNew)
            {
                case DIRCTION_INDEX_ENUM.LEFT_DOWN:
                    return true;
                case DIRCTION_INDEX_ENUM.LEFT:
                    return true;
                case DIRCTION_INDEX_ENUM.LEFT_UP:
                    return true;
                case DIRCTION_INDEX_ENUM.LEFTUP_MIDDLE_UP:
                    return true;
                case DIRCTION_INDEX_ENUM.LEFT_MIDDLE_LEFTUP:
                    return true;
                case DIRCTION_INDEX_ENUM.LEFTDOWN_MIDDLE_LEFT:
                    return true;
                case DIRCTION_INDEX_ENUM.DOWN_MIDDLE_LEFTDOWN:
                    return true;
                default:
                    return false;
            }
        }

        public static SPRITE_ACTION_ENUM ParseAnimationName(string name)
        {
            SPRITE_ACTION_ENUM action = SPRITE_ACTION_ENUM.WALK;
            switch (name)
            {
                case "Walk":
                    action = SPRITE_ACTION_ENUM.WALK;
                    break;
                case "Attack":
                    action = SPRITE_ACTION_ENUM.ATTACK;
                    break;
                case "Idle":
                    action = SPRITE_ACTION_ENUM.IDLE;
                    break;
                case "Dead":
                    action = SPRITE_ACTION_ENUM.DEAD;
                    break;
                case "Run":
                    action = SPRITE_ACTION_ENUM.RUN;
                    break;
                case "Hitfly":
                    action = SPRITE_ACTION_ENUM.HitFly;
                    break;
                default:
                    if (Debug.unityLogger.logEnabled) { Debug.LogError("查找不到相对应的动作，请检查相关动作是否存在" + name); }
                    break;
            }
            return action;
        }

        public static SPRITE_ACTION_ENUM GetAnimationTypeByName(string name)
        {
            SPRITE_ACTION_ENUM action = SPRITE_ACTION_ENUM.WALK;
            switch (name)
            {
                case "Walk":
                    action = SPRITE_ACTION_ENUM.WALK;
                    break;
                case "Attack":
                    action = SPRITE_ACTION_ENUM.ATTACK;
                    break;
                case "Idle":
                    action = SPRITE_ACTION_ENUM.IDLE;
                    break;
                case "Dead":
                    action = SPRITE_ACTION_ENUM.DEAD;
                    break;
                case "Run":
                    action = SPRITE_ACTION_ENUM.RUN;
                    break;
                case "Attack2":
                case "Hitfly":
                    action = SPRITE_ACTION_ENUM.HitFly;
                    break;
                case "soilder_BattererT1":
                    action = SPRITE_ACTION_ENUM.soilder_BattererT1;
                    break;
                case "soilder_BattererT2":
                    action = SPRITE_ACTION_ENUM.soilder_BattererT2;
                    break;
                case "soilder_BattererT3":
                    action = SPRITE_ACTION_ENUM.soilder_BattererT3;
                    break;
                case "soilder_BattererT4":
                    action = SPRITE_ACTION_ENUM.soilder_BattererT4;
                    break;
                case "soilder_BattererT5":
                    action = SPRITE_ACTION_ENUM.soilder_BattererT5;
                    break;
                case "soilder_RiderT1":
                    action = SPRITE_ACTION_ENUM.soilder_RiderT1;
                    break;
                case "soilder_RiderT2":
                    action = SPRITE_ACTION_ENUM.soilder_RiderT2;
                    break;
                case "soilder_RiderT3":
                    action = SPRITE_ACTION_ENUM.soilder_RiderT3;
                    break;
                case "soilder_RiderT4":
                    action = SPRITE_ACTION_ENUM.soilder_RiderT4;
                    break;
                case "soilder_RiderT5": 
                    action = SPRITE_ACTION_ENUM.soilder_RiderT5;
                    break;
                case "soilder_GunnerT1":
                    action = SPRITE_ACTION_ENUM.soilder_GunnerT1;
                    break;
                case "soilder_GunnerT2":
                    action = SPRITE_ACTION_ENUM.soilder_GunnerT2;
                    break;
                case "soilder_GunnerT3":
                    action = SPRITE_ACTION_ENUM.soilder_GunnerT3;
                    break;
                case "soilder_GunnerT4":
                    action = SPRITE_ACTION_ENUM.soilder_GunnerT4;
                    break;
                case "soilder_GunnerT5":
                    action = SPRITE_ACTION_ENUM.soilder_GunnerT5;
                    break;
                case "soilder_BombardierT1":
                    action = SPRITE_ACTION_ENUM.soilder_BombardierT1;
                    break;
                case "soilder_BombardierT2":
                    action = SPRITE_ACTION_ENUM.soilder_BombardierT2;
                    break;
                case "soilder_BombardierT3":
                    action = SPRITE_ACTION_ENUM.soilder_BombardierT3;
                    break;
                case "soilder_BombardierT4":
                    action = SPRITE_ACTION_ENUM.soilder_BombardierT4;
                    break;
                case "soilder_BombardierT5":
                    action = SPRITE_ACTION_ENUM.soilder_BombardierT5;
                    break;
                default:
                    if (Debug.unityLogger.logEnabled)
                    {
                        Debug.LogError("查找不到相对应的动作，请检查相关动作是否存在" + name);
                    }

                    break;
            }

            return action;
        }

        public static string GetAnimationNameByActionEnum(SPRITE_ACTION_ENUM action)
        {
            string result;
            switch (action)
            {
                case SPRITE_ACTION_ENUM.WALK:
                    result = "Walk";
                    break;
                case SPRITE_ACTION_ENUM.ATTACK:
                    result = "Attack";
                    break;
                case SPRITE_ACTION_ENUM.IDLE:
                    result = "Idle";
                    break;
                case SPRITE_ACTION_ENUM.DEAD:
                    result = "Dead";
                    break;
                case SPRITE_ACTION_ENUM.RUN:
                    result = "Run";
                    break;
                case SPRITE_ACTION_ENUM.HitFly:
                    result = "Hitfly";
                    break;
                case SPRITE_ACTION_ENUM.soilder_BattererT1:
                    result = "soilder_BattererT1";
                    break;
                case SPRITE_ACTION_ENUM.soilder_BattererT2:
                    result = "soilder_BattererT2";
                    break;
                case SPRITE_ACTION_ENUM.soilder_BattererT3:
                    result = "soilder_BattererT3";
                    break;
                case SPRITE_ACTION_ENUM.soilder_BattererT4:
                    result = "soilder_BattererT4";
                    break;
                case SPRITE_ACTION_ENUM.soilder_BattererT5:
                    result = "soilder_BattererT5";
                    break;
                case SPRITE_ACTION_ENUM.soilder_RiderT1:
                    result = "soilder_RiderT1";
                    break;
                case SPRITE_ACTION_ENUM.soilder_RiderT2:
                    result = "soilder_RiderT2";
                    break;
                case SPRITE_ACTION_ENUM.soilder_RiderT3:
                    result = "soilder_RiderT3";
                    break;
                case SPRITE_ACTION_ENUM.soilder_RiderT4:
                    result = "soilder_RiderT4";
                    break;
                case SPRITE_ACTION_ENUM.soilder_RiderT5:
                    result = "soilder_RiderT5";
                    break;
                case SPRITE_ACTION_ENUM.soilder_GunnerT1:
                    result = "soilder_GunnerT1";
                    break;
                case SPRITE_ACTION_ENUM.soilder_GunnerT2:
                    result = "soilder_GunnerT2";
                    break;
                case SPRITE_ACTION_ENUM.soilder_GunnerT3:
                    result = "soilder_GunnerT3";
                    break;
                case SPRITE_ACTION_ENUM.soilder_GunnerT4:
                    result = "soilder_GunnerT4";
                    break;
                case SPRITE_ACTION_ENUM.soilder_GunnerT5:
                    result = "soilder_GunnerT5";
                    break;
                case SPRITE_ACTION_ENUM.soilder_BombardierT1:
                    result = "soilder_BombardierT1";
                    break;
                case SPRITE_ACTION_ENUM.soilder_BombardierT2:
                    result = "soilder_BombardierT2";
                    break;
                case SPRITE_ACTION_ENUM.soilder_BombardierT3:
                    result = "soilder_BombardierT3";
                    break;
                case SPRITE_ACTION_ENUM.soilder_BombardierT4:
                    result = "soilder_BombardierT4";
                    break;
                case SPRITE_ACTION_ENUM.soilder_BombardierT5:
                    result = "soilder_BombardierT5";
                    break;
                default:
                    if (Debug.unityLogger.logEnabled)
                    {
                        Debug.LogError("查找不到相对应的动作，请检查相关动作是否存在" + action);
                    }

                    result = "Idle";
                    break;
            }

            return result;
        }
    }
}
